﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Security.AccessControl;

namespace project4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("Explorer.exe", @"/select,D:\c#-file\project4\NewFolder1");
        }

        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            listView1.Items.Clear();
            string myfolder = "D:\\c#-file\\project4\\NewFolder1";
            DirectoryInfo dir = new DirectoryInfo(myfolder);
            foreach (FileInfo f in dir.GetFiles())
            {
                if (!imageList1.Images.Keys.Contains(f.Extension))
                {
                    imageList1.Images.Add(f.Extension, Icon.ExtractAssociatedIcon(f.FullName));
                }

                ListViewItem lvi1 = new ListViewItem();
                lvi1.Text = f.Name;
                lvi1.ImageIndex = imageList1.Images.Keys.IndexOf(f.Extension);
                listView1.Items.Add(lvi1);
                comboBox1.Items.Add(f.Name);
                comboBox2.Items.Add(f.Name);
            }
        
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click_1(object sender, EventArgs e)
        {

        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            string path1 = "D:\\c#-file\\project4\\Data\\file3.txt";
            string path2 = "D:\\c#-file\\project4\\NewFolder1\\"+ comboBox1.SelectedItem.ToString();
            string path3 = "D:\\c#-file\\project4\\NewFolder1\\"+ comboBox2.SelectedItem.ToString();
            string s1, s2, s3;
            StreamReader r1 = new StreamReader(path2);
            StreamReader r2 = new StreamReader(path3);
            s1 = r1.ReadLine();
            s2 = r2.ReadLine();
            s3 = s1 + "\r\n" + s2;
            FileInfo f1 = new FileInfo(path1);
//            FileStream fs = new FileStream(path1, FileMode.Create);
            StreamWriter w1 = new StreamWriter(path1);
            w1.Write(s3);
            r1.Close();
            r2.Close();
            w1.Close();
        }

        private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e)
        {

        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}
